package ui
{
	import flash.display.NativeMenu;
	import flash.display.NativeMenuItem;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.system.Capabilities;
	
	import flashx.textLayout.elements.GlobalSettings;
	
	import mx.controls.FlexNativeMenu;
	import mx.core.Application;
	import mx.core.UIComponent;
	
	import spark.components.WindowedApplication;
	
	import util.err.SingletonInstantiationErr;

	public class ViewManager
	{
		private static var _instance:ViewManager;
		
		private var m_uiStage:UIComponent;
		
		private var m_stage:WindowedApplication;
		
		private var m_cmpCanvas:UICanvas;
		
		private var m_mainMenu:FlexNativeMenu;
		
		
		public function ViewManager()
		{
			if( _instance ) throw new SingletonInstantiationErr();
		}
		
		public static function instance():ViewManager
		{
			if( !_instance )
			{
				_instance = new ViewManager();
			}
			
			return _instance;
		}
		
		
		public function init( _stage:WindowedApplication ):void
		{
			m_stage = _stage;
			
			m_cmpCanvas = new UICanvas();
			
			m_stage.addElement( m_cmpCanvas );
			
			m_stage.addElement( new ComponentPanel );
			
			centre();
			
			configMainMenu();
			
			configListener();
			
			
			
		}
		
		private function configMainMenu():void
		{
			m_mainMenu = new FlexNativeMenu();
				
			var menuItem:NativeMenuItem = new NativeMenuItem( "文件" );
			
			m_mainMenu.nativeMenu.addItem( menuItem );
			
			m_stage.menu = m_mainMenu;
		
		}
		
		private function configControlBar():void
		{
			
		}
		
		
		private function configListener():void
		{
			m_stage.addEventListener( Event.RESIZE, onResize );
		}
		
		
		private function onResize( e:Event ):void
		{
			
		}
		
		private function centre():void
		{
			m_stage.move( ( Capabilities.screenResolutionX - m_stage.width ) / 2, ( Capabilities.screenResolutionY - m_stage.height ) / 2 );
		}
		
		
		
		
		
	}
}